{% extends "base.html" %}
{% load i18n %}
{% load pagination_tags %}
{% load socialaccount %}

{% block title %}{% trans "Project Dashboard" %}{% endblock %}

{% block dash-nav-projects %}active{% endblock %}

{% block content %}
  {% url "projects_import" as projects_import_url %}
  {% url "socialaccount_connections" as social_accounts %}

  <!-- BEGIN your projects list -->
  <div class="col-major project-dashboard-right">
    {% if project_list %}

      {% if filter.qs.count > 0 %}
        <div class="module-header">
          <h3>{% trans "Important Versions" %}</h3>
        </div>

        <div class="filter">
          {% autopaginate filter.qs 15 %}

          <!-- BEGIN filter list -->
          <div class="module">
            <div class="module-wrapper">

              <div class="module-list">
                <div class="module-list-wrapper">
                  <ul>
                    {% include "core/filter_list.html" %}
                  </ul>
                </div>
              </div>

            </div>
          </div>
          <!-- END filter list -->

          {% paginate %}

        </div>
      {% endif %}

      <div class="module">
        <div class="module-wrapper">

          <div class="module-header">
            {% block project_import_button %}
            <form method="get" action="{{ projects_import_url }}">
              <input type="submit" value="Import a Project" />
            </form>
            {% endblock %}
            <h3>{% trans "Projects" %}</h3>
          </div>

          <div class="module-list">
            <div class="module-list-wrapper">

              <ul>
                {% for project in project_list %}
                  <li class="module-item col-span">
                    <a href="{% url "projects_manage" project.slug %}">
                      {% block project-name %}
                        {{ project.name }}
                      {% endblock %}
                      {% with builds=project.builds.count %}
                        {% if builds == 0 %}
                          <span class="right quiet">
                            {% trans "No builds yet" %}
                          </span>
                        {% else %}
                          <span class="right quiet">
                            <span class="build-count">
                              {% if builds == 1 %}
                                {% trans "1 build" %}
                              {% else %}
                                {{ builds }} {% trans "builds" %}
                              {% endif %}
                            </span>
                            {% with build=project.get_latest_build %}
                              {% if build.success %}
                                <span class="build-state build-state-passing">{% trans "passing" %}</span>
                              {% else %}
                                <span class="build-state build-state-failing">{% trans "failing" %}</span>
                              {% endif %}
                            {% endwith %}
                          </span>
                        {% endif %}
                      {% endwith %}
                    </a>
                  </li>
                {% endfor %}
              </ul>

            </div>
          </div>
        </div>
      </div>

    {% else %}

      {% include 'projects/onboard_import.html' %}

    {% endif %}
  </div>
  <!-- END your projects list -->

  <!-- BEGIN project side bar -->
  <div class="col-minor project-dashboard-right">

    <!-- BEGIN search form -->
    <div class="module search search-dashboard">
      <form action="{% url 'search' %}" method="GET">
        <div class="text-input-wrapper search search-dashboard">
          <input type="text" name="q" class="search">
          {% if type %}
            <input type="hidden" name="type" value="{{ type }}">
          {% endif %}
          {% if taxonomy %}
            <input type="hidden" name="taxonomy" value="{{ taxonomy }}">
          {% endif %}
        </div>
      </form>
    </div>
    <!-- END search form -->

    <!-- BEGIN social account onboard -->
    {% get_social_accounts request.user as accounts %}
    {% if not accounts.github.0 %}
      <div class="module onboard onboard-accounts">
        <h3>Connect your Accounts</h3>

        <p>
          {% blocktrans %}
            Have a GitHub account? Connect your account and import your existing projects automatically.
          {% endblocktrans %}
        </p>

        <form method="get" action="{{ social_accounts }}">
          <input type="submit" value="Connect your Accounts" />
        </form>
      </div>
    {% endif %}
    <!-- END social account onboard -->

    {% block dashboard-onboard-extra %}
    {% endblock %}

    <div class="module info info-docs">
      <h3>Learn More</h3>
      <p>
        Check out the <a href="http://docs.readthedocs.io/en/latest/index.html">documentation for Read the Docs</a>.
        It contains lots of information about how to get the most out of RTD.
      </p>
    </div>
  </div>
  <!-- END project side bar -->
{% endblock %}
